import Mock from 'mockjs';

let List = []
const count = 10

for (let i = 0; i < count; i++) {
	List.push(Mock.mock({
		user_id: Mock.mock('@id()'),
		user: Mock.Random.last(),
		user_name: Mock.Random.cname(),
		addr: Mock.mock('@county(ture)'),
		email: Mock.Random.email(),
		last_date: Mock.Random.date(),
		'age|18-60': 1,
		sex: Mock.Random.integer(0, 1)
	}))
}

export default {
    getList:config => {
		return Mock.mock(List);
	},
	delDate:config =>{
		let user_id = parseInt(JSON.parse(config.body).user_id);
		List = List.filter(function(val){
			return val.user_id != user_id;
		})
		return List;
	},
	upDate:config =>{
		let user_id = parseInt(JSON.parse(config.body).user_id);
		List = List.filter(function(val){
			return val.user_id != user_id;
		})
		let obj = JSON.parse(config.body);
		// console.log(JSON.parse(options.body).params);
		// let id = parseInt(JSON.parse(options.body).params.obj.id);
		List = List.map(val => {  // 将需要替换的数据替换掉
			return val.id === obj.id ? obj : val ;
		});

		return List;
	}
}
